<?php

namespace System\library\logger\writers;

use System\library\Logger;

/**
 * <b>Class</b> :        Syslog<br>
 * <b>Fonction</b> :     Writer "Syslog" pour le logger, permet d'écrire les logs dans l'historique système
 * <br>
 * @version              1.0
 * @author               Dread <dreadlokeur@gmail.com>
 * @license              Licence publique générale GNU http://www.gnu.org/licenses/gpl.html
 * @copyright            Copyright 2011 - MidichloriansPHP and contributors
 * @package              System
 * @subpackage           library\logger\writers
 *
 * @see \SplObserver
 */
class Syslog implements \SplObserver {

    public function __construct($ident = 'MidichloriansPHP', $facility = LOG_USER) {
        openlog($identt, LOG_CONS, $facility);
    }

    public function __destruct() {
        closelog();
    }

    public function update(\SplSubject $subject, $lastLogOnly = false) {
        $logs = $subject->getLogs;
        if ($lastLogOnly) {
            $lastLog = array();
            $lastLog[] = end($logs);
            $logs = $lastLog;
        }
        foreach ($logs as &$log) {
            if (is_array($log)) {
                foreach ($log as &$l)
                    syslog($l->level, $l->message);
            } else
                syslog($log->level, $log->message);
        }
    }

}

?>
